{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "using LightGraphs\n",
    "using MetaGraphs\n",
    "using GraphMLReader\n",
    "using JSON"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "using BenchmarkTools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  12.003 s (93944749 allocations: 2.95 GiB)\n"
     ]
    }
   ],
   "source": [
    "g_file = \"/Users/zhangliye/julia_dev/GraphMLReader.jl/data/large_traffic_network.graphml\"\n",
    "@btime G = GraphMLReader.loadgraphml(g_file);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Set{Symbol} with 6 elements:\n",
       "  :type\n",
       "  :name\n",
       "  :lat\n",
       "  :original_id\n",
       "  :id_source\n",
       "  :lon"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "node_fields(G)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Set{Symbol} with 5 elements:\n",
       "  :bike_lane\n",
       "  :type\n",
       "  :name\n",
       "  :source_id\n",
       "  :length"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "edge_fields(G)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "metaweights"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ids = gmlid2metaid(G)\n",
    "weightfield!(G, :length)\n",
    "w = weights(G)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000-element Array{Any,1}:\n",
       " \"149083\"\n",
       " \"151452\"\n",
       " \"154877\"\n",
       " \"14176\"\n",
       " \"113331\"\n",
       " \"25972\"\n",
       " \"30398\"\n",
       " \"34958\"\n",
       " \"89505\"\n",
       " \"32479\"\n",
       " \"11866\"\n",
       " \"156147\"\n",
       " \"78982\"\n",
       " ⋮\n",
       " \"19052\"\n",
       " \"24529\"\n",
       " \"46792\"\n",
       " \"106611\"\n",
       " \"140718\"\n",
       " \"4643\"\n",
       " \"27514\"\n",
       " \"54178\"\n",
       " \"106453\"\n",
       " \"31290\"\n",
       " \"76240\"\n",
       " \"31142\""
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file_path = \"/Users/zhangliye/julia_dev/GraphMLReader.jl/data/origin.json\"\n",
    "origin_ids = JSON.parsefile(file_path)\n",
    "length(origin_ids)\n",
    "origin_ids"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "id_origin = '2'\n",
      "id_origin = '1'\n",
      "id_origin = '8'\n",
      "id_origin = '8'\n",
      "id_origin = '5'\n"
     ]
    }
   ],
   "source": [
    "for id_origin in origin_ids[:20]\n",
    "    @show id_origin\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "ename": "UndefVarError",
     "evalue": "UndefVarError: ts not defined",
     "output_type": "error",
     "traceback": [
      "UndefVarError: ts not defined",
      "",
      "Stacktrace:",
      " [1] top-level scope at In[24]:1"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  0.685092 seconds (491 allocations: 6.737 MiB)\n",
      "  0.326103 seconds (464 allocations: 6.735 MiB)\n",
      "  0.343768 seconds (384 allocations: 6.740 MiB)\n",
      "  0.324103 seconds (426 allocations: 6.746 MiB)\n",
      "  0.339331 seconds (378 allocations: 6.739 MiB)\n",
      "  0.332866 seconds (380 allocations: 6.726 MiB)\n",
      "  0.339515 seconds (323 allocations: 6.719 MiB)\n",
      "  0.395761 seconds (38.32 k allocations: 8.672 MiB, 11.75% gc time)\n",
      "  0.335274 seconds (344 allocations: 6.721 MiB)\n",
      "  0.326692 seconds (424 allocations: 6.741 MiB)\n",
      "  0.327877 seconds (425 allocations: 6.730 MiB)\n",
      "  0.328120 seconds (386 allocations: 6.726 MiB)\n",
      "  0.343189 seconds (371 allocations: 6.724 MiB)\n",
      "  0.346684 seconds (357 allocations: 6.738 MiB)\n",
      "  0.348420 seconds (416 allocations: 6.729 MiB)\n",
      "  0.332005 seconds (333 allocations: 6.736 MiB)\n",
      "  0.322998 seconds (341 allocations: 6.721 MiB)\n",
      "  0.332552 seconds (396 allocations: 6.743 MiB)\n",
      "  0.319058 seconds (545 allocations: 6.743 MiB)\n",
      "  0.327623 seconds (341 allocations: 6.721 MiB)\n"
     ]
    }
   ],
   "source": [
    "for id_origin in origin_ids[1:20]\n",
    "    id = ids[ id_origin ]\n",
    "    @time rst = dijkstra_shortest_paths(G, [id], w)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "@timed\n",
       "\\end{verbatim}\n",
       "A macro to execute an expression, and return the value of the expression, elapsed time, total bytes allocated, garbage collection time, and an object with various memory allocation counters.\n",
       "\n",
       "See also \\href{@ref}{\\texttt{@time}}, \\href{@ref}{\\texttt{@timev}}, \\href{@ref}{\\texttt{@elapsed}}, and \\href{@ref}{\\texttt{@allocated}}.\n",
       "\n",
       "\\begin{verbatim}\n",
       "julia> val, t, bytes, gctime, memallocs = @timed rand(10^6);\n",
       "\n",
       "julia> t\n",
       "0.006634834\n",
       "\n",
       "julia> bytes\n",
       "8000256\n",
       "\n",
       "julia> gctime\n",
       "0.0055765\n",
       "\n",
       "julia> fieldnames(typeof(memallocs))\n",
       "(:allocd, :malloc, :realloc, :poolalloc, :bigalloc, :freecall, :total_time, :pause, :full_sweep)\n",
       "\n",
       "julia> memallocs.total_time\n",
       "5576500\n",
       "\\end{verbatim}\n"
      ],
      "text/markdown": [
       "```\n",
       "@timed\n",
       "```\n",
       "\n",
       "A macro to execute an expression, and return the value of the expression, elapsed time, total bytes allocated, garbage collection time, and an object with various memory allocation counters.\n",
       "\n",
       "See also [`@time`](@ref), [`@timev`](@ref), [`@elapsed`](@ref), and [`@allocated`](@ref).\n",
       "\n",
       "```julia-repl\n",
       "julia> val, t, bytes, gctime, memallocs = @timed rand(10^6);\n",
       "\n",
       "julia> t\n",
       "0.006634834\n",
       "\n",
       "julia> bytes\n",
       "8000256\n",
       "\n",
       "julia> gctime\n",
       "0.0055765\n",
       "\n",
       "julia> fieldnames(typeof(memallocs))\n",
       "(:allocd, :malloc, :realloc, :poolalloc, :bigalloc, :freecall, :total_time, :pause, :full_sweep)\n",
       "\n",
       "julia> memallocs.total_time\n",
       "5576500\n",
       "```\n"
      ],
      "text/plain": [
       "\u001b[36m  @timed\u001b[39m\n",
       "\n",
       "  A macro to execute an expression, and return the value of the expression,\n",
       "  elapsed time, total bytes allocated, garbage collection time, and an object\n",
       "  with various memory allocation counters.\n",
       "\n",
       "  See also \u001b[36m@time\u001b[39m, \u001b[36m@timev\u001b[39m, \u001b[36m@elapsed\u001b[39m, and \u001b[36m@allocated\u001b[39m.\n",
       "\n",
       "\u001b[36m  julia> val, t, bytes, gctime, memallocs = @timed rand(10^6);\u001b[39m\n",
       "\u001b[36m  \u001b[39m\n",
       "\u001b[36m  julia> t\u001b[39m\n",
       "\u001b[36m  0.006634834\u001b[39m\n",
       "\u001b[36m  \u001b[39m\n",
       "\u001b[36m  julia> bytes\u001b[39m\n",
       "\u001b[36m  8000256\u001b[39m\n",
       "\u001b[36m  \u001b[39m\n",
       "\u001b[36m  julia> gctime\u001b[39m\n",
       "\u001b[36m  0.0055765\u001b[39m\n",
       "\u001b[36m  \u001b[39m\n",
       "\u001b[36m  julia> fieldnames(typeof(memallocs))\u001b[39m\n",
       "\u001b[36m  (:allocd, :malloc, :realloc, :poolalloc, :bigalloc, :freecall, :total_time, :pause, :full_sweep)\u001b[39m\n",
       "\u001b[36m  \u001b[39m\n",
       "\u001b[36m  julia> memallocs.total_time\u001b[39m\n",
       "\u001b[36m  5576500\u001b[39m"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "?@timed"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.4.1",
   "language": "julia",
   "name": "julia-1.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.4.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
